package com.xingkeduo.business.user.service;

import com.xingkeduo.dao.database.DatabaseAccessObject;
import com.xingkeduo.pojo.query.WechatQrcodeQO;
import com.xingkeduo.pojo.table.WechatQrcodeTO;
import com.xingkeduo.util.pojo.exception.DataException;
import com.xingkeduo.util.tool.CommonUtil;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description:
 * @Author:gaozifeng
 * @Date 2019/7/10 16:44
 **/
@Component
public class WechatQrcodeService {
    private static final String NAMESPACE = CommonUtil.formatNamespace(WechatQrcodeTO.class);
    @Resource(name = "mysqlUserMasterDao")
    private DatabaseAccessObject<WechatQrcodeTO, WechatQrcodeQO> dao;

    /** 查询
     * @param query:
     * @return : void
     * @author : gaozifeng
     * @date : 2019/7/11 15:19
     */
    public WechatQrcodeTO selectByPrimary(long id) throws Throwable {
        return dao.select(NAMESPACE, id);
    }

    /** 查询
     * @param query:
     * @return : void
     * @author : gaozifeng
     * @date : 2019/7/11 15:19
     */
    public List<WechatQrcodeTO> selectByQuery(WechatQrcodeQO query) throws Throwable {
        return dao.select(NAMESPACE, query);
    }

    /** 查询
     * @param query:
     * @return : void
     * @author : gaozifeng
     * @date : 2019/7/11 15:19
     */
    public List<Long> selectByListId(WechatQrcodeQO query) throws Throwable {
        return dao.selectIndex(NAMESPACE, query);
    }

    /** 总数
     * @param query:
     * @return : void
     * @author : gaozifeng
     * @date : 2019/7/11 15:19
     */
    public int count(WechatQrcodeQO query) throws Throwable {
        return dao.selectCount(NAMESPACE, query);
    }

    /** 新增
     * @param table:
     * @return : void
     * @author : gaozifeng
     * @date : 2019/7/11 15:19
     */
    @Transactional
    public void insert(WechatQrcodeTO table) throws Throwable {
        if (dao.insert(NAMESPACE, table) < 1)
            throw new DataException(DataException.Type.FAIL, "新增二维码记录");
    }

    /** 修改
     * @param table:
     * @return : void
     * @author : gaozifeng
     * @date : 2019/7/11 15:19
     */
    @Transactional
    public void update(WechatQrcodeTO table) throws Throwable {
        if (dao.update(NAMESPACE, table) < 1)
            throw new DataException(DataException.Type.FAIL, "修改二维码记录");
    }
}
